<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content=
    "application/xhtml+xml; charset=iso-8859-1" />
    <title>
      7.13.&nbsp;The Bash Shell Startup Files
    </title>
    <link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="stylesheet" href="../stylesheets/lfs-print.css" type=
    "text/css" media="print" />
  </head>
  <body class="lfs" id="lfs-7.3">
    <div class="navheader">
      <h4>
        Linux From Scratch - Version 7.3
      </h4>
      <h3>
        Chapter&nbsp;7.&nbsp;Setting Up System Bootscripts
      </h3>
      <ul>
        <li class="prev">
          <a accesskey="p" href="site.html" title="The rc.site File">Prev</a>
          <p>
            The rc.site File
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="inputrc.html" title=
          "Creating the /etc/inputrc File">Next</a>
          <p>
            Creating the /etc/inputrc File
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter07.html" title=
          "Chapter&nbsp;7.&nbsp;Setting Up System Bootscripts">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Linux From Scratch - Version 7.3">Home</a>
        </li>
      </ul>
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <h1 class="sect1">
        <a id="ch-scripts-profile" name="ch-scripts-profile"></a>7.13. The
        Bash Shell Startup Files
      </h1>
      <p>
        The shell program <span class=
        "command"><strong>/bin/bash</strong></span> (hereafter referred to as
        &ldquo;<span class="quote">the shell</span>&rdquo;) uses a collection
        of startup files to help create an environment to run in. Each file
        has a specific use and may affect login and interactive environments
        differently. The files in the <code class="filename">/etc</code>
        directory provide global settings. If an equivalent file exists in
        the home directory, it may override the global settings.
      </p>
      <p>
        An interactive login shell is started after a successful login, using
        <span class="command"><strong>/bin/login</strong></span>, by reading
        the <code class="filename">/etc/passwd</code> file. An interactive
        non-login shell is started at the command-line (e.g., <code class=
        "prompt">[prompt]$</code><span class=
        "command"><strong>/bin/bash</strong></span>). A non-interactive shell
        is usually present when a shell script is running. It is
        non-interactive because it is processing a script and not waiting for
        user input between commands.
      </p>
      <p>
        For more information, see <span class="command"><strong>info
        bash</strong></span> under the <span class="emphasis"><em>Bash
        Startup Files and Interactive Shells</em></span> section.
      </p>
      <p>
        The files <code class="filename">/etc/profile</code> and <code class=
        "filename">~/.bash_profile</code> are read when the shell is invoked
        as an interactive login shell.
      </p>
      <p>
        The base <code class="filename">/etc/profile</code> below sets some
        environment variables necessary for native language support. Setting
        them properly results in:
      </p>
      <div class="itemizedlist">
        <ul>
          <li>
            <p>
              The output of programs translated into the native language
            </p>
          </li>
          <li>
            <p>
              Correct classification of characters into letters, digits and
              other classes. This is necessary for <span class=
              "command"><strong>bash</strong></span> to properly accept
              non-ASCII characters in command lines in non-English locales
            </p>
          </li>
          <li>
            <p>
              The correct alphabetical sorting order for the country
            </p>
          </li>
          <li>
            <p>
              Appropriate default paper size
            </p>
          </li>
          <li>
            <p>
              Correct formatting of monetary, time, and date values
            </p>
          </li>
        </ul>
      </div>
      <p>
        Replace <em class="replaceable"><code>&lt;ll&gt;</code></em> below
        with the two-letter code for the desired language (e.g.,
        &ldquo;<span class="quote">en</span>&rdquo;) and <em class=
        "replaceable"><code>&lt;CC&gt;</code></em> with the two-letter code
        for the appropriate country (e.g., &ldquo;<span class=
        "quote">GB</span>&rdquo;). <em class=
        "replaceable"><code>&lt;charmap&gt;</code></em> should be replaced
        with the canonical charmap for your chosen locale. Optional modifiers
        such as &ldquo;<span class="quote">@euro</span>&rdquo; may also be
        present.
      </p>
      <p>
        The list of all locales supported by Glibc can be obtained by running
        the following command:
      </p>
      <pre class="userinput">
<kbd class="command">locale -a</kbd>
</pre>
      <p>
        Charmaps can have a number of aliases, e.g., &ldquo;<span class=
        "quote">ISO-8859-1</span>&rdquo; is also referred to as
        &ldquo;<span class="quote">iso8859-1</span>&rdquo; and
        &ldquo;<span class="quote">iso88591</span>&rdquo;. Some applications
        cannot handle the various synonyms correctly (e.g., require that
        &ldquo;<span class="quote">UTF-8</span>&rdquo; is written as
        &ldquo;<span class="quote">UTF-8</span>&rdquo;, not
        &ldquo;<span class="quote">utf8</span>&rdquo;), so it is safest in
        most cases to choose the canonical name for a particular locale. To
        determine the canonical name, run the following command, where
        <em class="replaceable"><code>&lt;locale name&gt;</code></em> is the
        output given by <span class="command"><strong>locale
        -a</strong></span> for your preferred locale (&ldquo;<span class=
        "quote">en_GB.iso88591</span>&rdquo; in our example).
      </p>
      <pre class="userinput">
<kbd class="command">LC_ALL=<em class=
"replaceable"><code>&lt;locale name&gt;</code></em> locale charmap</kbd>
</pre>
      <p>
        For the &ldquo;<span class="quote">en_GB.iso88591</span>&rdquo;
        locale, the above command will print:
      </p>
      <pre class="screen">
<code class="computeroutput">ISO-8859-1</code>
</pre>
      <p>
        This results in a final locale setting of &ldquo;<span class=
        "quote">en_GB.ISO-8859-1</span>&rdquo;. It is important that the
        locale found using the heuristic above is tested prior to it being
        added to the Bash startup files:
      </p>
      <pre class="userinput">
<kbd class="command">LC_ALL=&lt;locale name&gt; locale language
LC_ALL=&lt;locale name&gt; locale charmap
LC_ALL=&lt;locale name&gt; locale int_curr_symbol
LC_ALL=&lt;locale name&gt; locale int_prefix</kbd>
</pre>
      <p>
        The above commands should print the language name, the character
        encoding used by the locale, the local currency, and the prefix to
        dial before the telephone number in order to get into the country. If
        any of the commands above fail with a message similar to the one
        shown below, this means that your locale was either not installed in
        Chapter 6 or is not supported by the default installation of Glibc.
      </p>
      <pre class="screen">
<code class=
"computeroutput">locale: Cannot set LC_* to default locale: No such file or directory</code>
</pre>
      <p>
        If this happens, you should either install the desired locale using
        the <span class="command"><strong>localedef</strong></span> command,
        or consider choosing a different locale. Further instructions assume
        that there are no such error messages from Glibc.
      </p>
      <p>
        Some packages beyond LFS may also lack support for your chosen
        locale. One example is the X library (part of the X Window System),
        which outputs the following error message if the locale does not
        exactly match one of the character map names in its internal files:
      </p>
      <pre class="screen">
<code class=
"computeroutput">Warning: locale not supported by Xlib, locale set to C</code>
</pre>
      <p>
        In several cases Xlib expects that the character map will be listed
        in uppercase notation with canonical dashes. For instance,
        "ISO-8859-1" rather than "iso88591". It is also possible to find an
        appropriate specification by removing the charmap part of the locale
        specification. This can be checked by running the <span class=
        "command"><strong>locale charmap</strong></span> command in both
        locales. For example, one would have to change
        "de_DE.ISO-8859-15@euro" to "de_DE@euro" in order to get this locale
        recognized by Xlib.
      </p>
      <p>
        Other packages can also function incorrectly (but may not necessarily
        display any error messages) if the locale name does not meet their
        expectations. In those cases, investigating how other Linux
        distributions support your locale might provide some useful
        information.
      </p>
      <p>
        Once the proper locale settings have been determined, create the
        <code class="filename">/etc/profile</code> file:
      </p>
      <pre class="userinput">
<kbd class="command">cat &gt; /etc/profile &lt;&lt; "EOF"
<code class="literal"># Begin /etc/profile

export LANG=<em class=
"replaceable"><code>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</code></em>

# End /etc/profile</code>
EOF</kbd>
</pre>
      <p>
        The &ldquo;<span class="quote">C</span>&rdquo; (default) and
        &ldquo;<span class="quote">en_US</span>&rdquo; (the recommended one
        for United States English users) locales are different.
        &ldquo;<span class="quote">C</span>&rdquo; uses the US-ASCII 7-bit
        character set, and treats bytes with the high bit set as invalid
        characters. That's why, e.g., the <span class=
        "command"><strong>ls</strong></span> command substitutes them with
        question marks in that locale. Also, an attempt to send mail with
        such characters from Mutt or Pine results in non-RFC-conforming
        messages being sent (the charset in the outgoing mail is indicated as
        &ldquo;<span class="quote">unknown 8-bit</span>&rdquo;). So you can
        use the &ldquo;<span class="quote">C</span>&rdquo; locale only if you
        are sure that you will never need 8-bit characters.
      </p>
      <p>
        UTF-8 based locales are not supported well by many programs. Work is
        in progress to document and, if possible, fix such problems, see
        <a class="ulink" href=
        "http://www.linuxfromscratch.org/blfs/view/svn/introduction/locale-issues.html">
        http://www.linuxfromscratch.org/blfs/view/svn/introduction/locale-issues.html</a>.
      </p>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="site.html" title="The rc.site File">Prev</a>
          <p>
            The rc.site File
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="inputrc.html" title=
          "Creating the /etc/inputrc File">Next</a>
          <p>
            Creating the /etc/inputrc File
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter07.html" title=
          "Chapter&nbsp;7.&nbsp;Setting Up System Bootscripts">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Linux From Scratch - Version 7.3">Home</a>
        </li>
      </ul>
    </div>
  </body>
</html>
